package com.atcumt.meituan;

import java.math.BigInteger;
import java.util.Scanner;

/* 
 * 长城数
 * 输入：
 * 6
 * 1 1 4 5 1 4
 * 输出：11
 * 得到的长城为 {4, 5, 4, 5, 4, 5}
 */
public class Q5 {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
        }

        int res = solve(nums);
        System.out.println(res);
        sc.close();
    }
    
    private static int solve(int[] nums) {
        int oddMax = -1; // 奇数
        int evenMax = -1; // 偶数
        // BigInteger count = new BigInteger("0");
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i % 2 == 0) {
                oddMax = Math.max(oddMax, nums[i]);
            } else {
                evenMax = Math.max(evenMax, nums[i]);
            }
        }
        if (oddMax == evenMax) {
            evenMax++;
        }
        for (int i = 0; i < nums.length; i++) {
            int temp = i % 2 == 0 ? oddMax - nums[i] : evenMax - nums[i];
            count += temp;
        }
        return count;
    }
}
